package br.ufrgs.meetapp.models;

import java.util.ArrayList;

import br.ufrgs.meetapp.enums.MessageCode;

public class SettingsMessage extends MFTMessage {
	
	private String messageBody;
	
	public SettingsMessage(MFTSettings settings) {
		
		ArrayList<SettingsEntry> settingsEntryList = settings.getSettingsEntryList();
		
		messageBody = "";
		for (SettingsEntry settingsEntry : settingsEntryList) {
			messageBody += settingsEntry.getKey().getServerLabel()+":"+settingsEntry.getValue()+"\r\n";
		}
	}
	
	/***
	 * Returns the serialized identification message 
	 * @return Byte array to be send to MFT listener
	 */
	@Override
	public byte[] getSerializedMessage() {
		
		createByteMessage((getStringByteArray(messageBody).length - BYTE_ORDER_MARK_BYTES), MessageCode.SETTINGS.getByteCode());
		writeStringAtMessageIndex(messageBody, MESSAGE_BODY_INDEX);
		finishByteMessage();
		
		return byteMessage;
	}
	
	
}
